// 服务器基础路径：
const baseURL = 'http://nocat.life:3012';

// 1、封装请求方法：
const request = async (url, method, data, isLoading = true) => {

	// 请求开始前，展示loading动画：
	if (isLoading) {
		uni.showLoading({
			title: '加载中'
		});
	}

	const res = await uni.request({
		url: baseURL + url,
		method,
		data,
		timeout: 5000,
		header: {
			Authorization: uni.getStorageSync('user_token')
		}
	});

	// 请求结束，隐藏loading动画：
	uni.hideLoading();

	return res.data;
}

// 2、根据请求类型封装请求方法：
export const httpGet = (url, data, isLoading) => {
	return request(url, 'GET', data, isLoading);
};
export const httpPost = (url, data, isLoading) => {
	return request(url, 'POST', data, isLoading);
};
export const httpDelete = (url, data, isLoading) => {
	return request(url, 'DELETE', data, isLoading);
};
export const httpPut = (url, data, isLoading) => {
	return request(url, 'PUT', data, isLoading);
};